#!/bin/bash

# 检查根目录中是否存在 esp 和 .espressif 文件夹
esp_exists=false
espressif_exists=false

if [ -d "$HOME/esp" ]; then
    esp_exists=true
fi

if [ -d "$HOME/.espressif" ]; then
    espressif_exists=true
fi

# 如果存在任何一个文件夹，提示用户是否删除
if [ "$esp_exists" = true ] || [ "$espressif_exists" = true ]; then
    echo "您当前目录下包含以下目录："
    if [ "$esp_exists" = true ]; then
        echo "  - ~/esp"
    fi
    if [ "$espressif_exists" = true ]; then
        echo "  - ~/.espressif"
    fi
    echo "是否进行删除？(Y/N):"
    
    # 读取用户输入
    read -r response
    
    # 根据用户输入决定是否删除
    if [ "$response" = "Y" ] || [ "$response" = "y" ]; then
        if [ "$esp_exists" = true ]; then
            rm -rf "$HOME/esp"
            echo "已删除 ~/esp 目录"
        fi
        if [ "$espressif_exists" = true ]; then
            rm -rf "$HOME/.espressif"
            echo "已删除 ~/.espressif 目录"
        fi
        echo "删除完成。"
    else
        echo "取消删除。"
    fi
else
    echo "当前目录下不包含 ~/esp 和 ~/.espressif 目录。"
fi
